<?php
/*
 * ambikuk@technolyze.net
 * 
 */

define('POST_TYPE', 'member-data');
add_action('user_register','add_member');
add_action('delete_user', 'delete_member');
function add_member(){
	$post = $_POST;
	$username = htmlspecialchars($post['user_login']);
	
	if(isset($post['username'])&&$post['username']!=''){
		$username = $post['username'];
	}
	
	// Create post object	
  $my_post = array(
     'post_title' => $username,
     'post_content' => '',
     'post_status' => 'publish',
     'post_author' => 1,
		 'post_type' => POST_TYPE,
  );

// Insert the post into the database
  wp_insert_post( $my_post );
}

function delete_member($user_id){
	global $wpdb;	
	$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE ID = %d",$user_id));
	$username = $user->user_login;
//	var_dump($username);  exit;
	$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->posts WHERE post_type = %s AND post_title = %s", POST_TYPE,$username));
}

function getDataMember($username){
	global $wpdb;
	$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login='".$username."'");
	$uid = $user->ID;
	$curauth = get_userdata($uid);
	$CField = get_user_option ("s2member_custom_fields", $uid);
	$created = date("F jS, Y", strtotime($curauth->user_registered));	
	
	$html = "<h2>$curauth->display_name</h2>\n";	
	$html .= get_avatar($uid,150);	
	$html .= "<br /><strong>Joined on:</strong>  " . $created . "</br>";
	$html .= "<ul>";
	$html .= "<li>Telephone : ".$CField['telephone']."</li>";
	$html .= "<li>Hp : ".$CField['handphone']."</li>";
	$html .= "<li>Alamat : ".$CField['address']."</li>";
	$html .= "<li>Twitter : ".$CField['twitter']."</li>";
	$html .= "<li>Website : ".$CField['website']."</li>";
	$html .= "<li>Facebook : ".$CField['facebook']."</li>";
	$html .= "<li>Skype : ".$CField['skype']."</li>";
	$html .= "<li>Skill : ".$CField['skill']."</li>";
	$html .= "<li>Tentang Saya : ".$CField['description']."</li>";
	$html .= "<li>group : ".$CField['group']."</li>";
	$html .= "</ul>";
	
	return $html;
}


